<template>
	<div id="nav-wapper">
		<div id="index-nav" :class="{ active: mobileMenuVisibity }">
			<h1>HuXY'Blog</h1>
			<div class="nav-group">
				<router-link class="nav-item" v-for="(item, index) in navs" :key="index" :to="item.to">
					<i :class="item.icon"></i>
					<span>{{ item.lable }}</span>
				</router-link>
			</div>
			<div class="nav-down-wapper">
				<div class="user">
					<div class="user-face">
						<el-image v-if="user" :src="user.head"></el-image>
						<el-image v-else><div slot="error" class="no-login" @click="showLoginBox = true">登录</div></el-image>
					</div>
					<div class="logout" v-if="user" @click="logOut">退出登录</div>
				</div>
			</div>
		</div>
		<div class="mobile">
			<div class="header">
				<span class="unfold" @click="changeNavVisibity"><i class="el-icon-s-unfold"></i></span>
				<span class="search"><i class="el-icon-search"></i></span>
			</div>
			<div class="mask" :class="{ show: mobileMenuVisibity }" @click="changeNavVisibity"></div>
		</div>
		<loginBox v-model="showLoginBox"></loginBox>
	</div>
</template>

<script>
import loginBox from '@/components/LoginBox.vue';
import QC from '@/assets/js/qc_jssdk.js';
import {$post} from '@/puigins/request.js'
export default {
	data() {
		return {
			navs: [
				{
					icon: 'el-icon-s-home',
					lable: '首页',
					to: '/'
				}
			],
			mobileMenuVisibity: false,
			src: '',
			showLoginBox: false
		};
	},
	mounted() {
		// console.log("btn-qq-login",QC.Login,document.getElementById('btn-qq-login'))
		// QC.Login({
		// 	btnId: 'btn-qq-login',
		// 	size: 'B_M'
		// });
	},
	methods: {
		changeNavVisibity() {
			this.mobileMenuVisibity = !this.mobileMenuVisibity;
		},
		logOut() {
			this.$confirm('确定退出登录?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			})
				.then(() => {
					$post('/user/logOut').then(res => {
						if (res.code == 200) {
							this.$store.commit('user/logOut');
							this.history = [];
							this.historyLength = 0;
							this.selected = [];
							this.showSelect = false;
						} else {
							this.$msgError(res);
						}
					});
				})
				.catch(() => {});
		}
	},
	watch: {
		$route() {
			this.mobileMenuVisibity = false;
			document.getElementById('index').scrollTo(0, 0);
		}
	},
	components: {
		loginBox
	},
	computed: {
		user() {
			return this.$store.state.user.user;
		}
	}
};
</script>

<style lang="scss">
#index-nav {
	width: 20%;
	position: fixed;
	left: 0;
	top: 0;
	// z-index: 1001;
	transition: 0.5s;
	height: 100%;
	display: flex;
	align-items: center;
	flex-direction: column;
	background-color: #fff;
	// z-index: -1;
	h1 {
		cursor: pointer;
		margin: 40px 0 30px;
		&:hover {
		}
	}
	.nav-down-wapper {
		flex: 1;
		width: 100%;
		display: flex;
		flex-direction: column-reverse;
		.user {
			display: flex;
			justify-content: space-around;
			margin-bottom: 15px;
			height: 40px;
			align-items: center;
			.user-face {
				width: 40px;
				height: 100%;
				cursor: pointer;
				.el-image {
					text-align: center;
					width: 100%;
					height: 100%;
					.no-login {
						width: 100%;
						height: 100%;
						display: flex;
						justify-content: center;
						align-items: center;
						font-size: 14px;
						color: #c0c4cc;
						vertical-align: middle;
						background-color: #f5f7fa;
						border-radius: 50%;
						&:hover {
							color: #f00;
						}
					}
				}
			}
		}
	}
	.nav-group {
		display: flex;
		flex-direction: column;
		align-items: center;
		.nav-item {
			padding: 10px 30px;
			margin: 10px 0;
			cursor: pointer;
			outline: none;
			color: #000;
			width: 100%;
			display: flex;
			i {
				padding-right: 5px;
			}
			span {
				flex: 1;
				text-align: justify;
				// height: 1rem;
				overflow: hidden;
				line-height: 1rem;
				height: 1rem;
				&:after {
					display: inline-block;
					width: 100%;
					height: 0;
					content: '';
				}
			}
		}
	}
}
#nav-wapper {
	.mobile {
		display: none;
	}
}
@media screen and (max-width: 768px) {
	#nav-wapper {
		.mobile {
			display: block;
			position: fixed;
			top: 0;
			left: 0;
			height: 40px;
			width: 100%;
			z-index: 4;
			.header {
				padding: 10px 12px;
				background-color: #fff;
				font-size: 24px;
				// text-align: right;
				z-index: 8;
				display: flex;
				justify-content: space-between;
			}
			.mask {
				background-color: rgba(0, 0, 0, 0.52);
				width: 100%;
				height: 100%;
				position: fixed;
				z-index: 5;
				opacity: 0;
				visibility: hidden;
				top: 0;
				left: 0;
			}
			.show {
				opacity: 1;
				visibility: visible;
			}
		}
	}
	#index-nav {
		transform: translateX(-270px);
		width: 270px;
		z-index: 1001;
		height: 100%;
		h1 {
			margin: 10px 0 30px;
		}
	}
	.active {
		transform: translateX(0) !important;
	}
}
</style>
